const fs = require('fs');
const path = require('path');

module.exports = function generateModuleDescriptor(packageJson) {
  console.log('start generate moduleDescriptor.json...');
  const stripes = packageJson.stripes || {};
  const moduleDescriptor = {
    id: `${packageJson.name.replace(/^@/, '').replace('/', '_')}-${packageJson.version}`,
    name: packageJson.description,
    permissionSets: stripes.permissionSets || [],
  };

  const file = path.join('./', 'moduleDescriptor.json');
  const text = JSON.stringify(moduleDescriptor);

  fs.writeFileSync(file, text);
  console.log('build moduleDescriptor.json success!!!');
};
